<?
/*  专门处理评论的Action，目前暂时对应的表a_comment
 * 
*/
class CommentAction extends Action {
  private $_dev = 0;//暂时没用到
  private $_isAjax = 0;//暂时还弄aja情况
  private $_uid = 0;
  private $_username = '';
  private $_checkAction=array('save');//检查登录状态的action

  function _initialize() {
    $this->_dev = C("DEV_FLAG");
    $this->_uid = $_COOKIE['tpxslmluserid'];
    $this->_username = $_COOKIE['tpxslmlusername'];
    $this->assign("waitSecond", 1);
    if (in_array(strtolower(ACTION_NAME),$this->_checkAction)) {
      if(!$_COOKIE['tpxslmlusername'] || !$_COOKIE['tpxslmluserid'] || !$_COOKIE['tpxslmlgroupid'] || !$_COOKIE['tpxslmlrnd']) {
        $this->assign("jumpUrl", "/pw8/login.php");
        $this->error("您还没有登陆，请登录");
      }
    }
  }

  /*  params: type      类型：1-供求
   *  params: sub_id    子类型，根据不同的type，sub也不同   [type=1]  a_require.id
   *  params: content   评论的内容
  */
  public function save() {
    if ($_POST['type'] == 1) {
      $m = M('AComment');
      $data = array(uid=>$this->_uid,username=>$this->_username,content=>$_POST['content'],type=>$_POST['type'],sub_id=>$_POST['sub_id']);
      $rt = $m->add($data);
      if ($rt == false) $this->ajaxReturn('','评论失败',2);
      $this->ajaxReturn('','评论成功',1);
    }else {
      $this->ajaxReturn('','这个action目前只能评论供求的信息',2);
    }
  }
  
  /*  获取评论列表
  */
  public function lists($type,$subID,$uid=0){
    $m = M('AComment');
    $where = 'type = '.$type.' and sub_id = '.$subID;
    if ($uid > 0) $where .= ' and uid = '.$uid;
    $list = $m->where($where)->order('create_time desc')->select();
    return $list;
  }
}
?>